﻿@model IEnumerable<WebUI.Models.DepartmentProfile>
@{
    int dColor = 0;
}
<script type="text/javascript">
    function initEditField(id, name, type, length) {
        $('#RAI_ID').val(id);
        $('#RAI_Name').val(name);
        $('#RAI_Length').val(length);
        if (type == 'System.String' || type == 'System.Int32' || type == 'System.Double') {
            $('#RAI_Length').attr('readonly', false).removeClass('readonly');
        } else {
            $('#RAI_Length').attr('readonly', true).addClass('readonly');
        }
        $('#EditFieldSet').show();
        $('#EditError').html('').hide();
    }
    function validateEdit() {
        if ($('#RAI_Name').val() == '') {
            $('#EditError').html('属性名称不能为空！').show();
            return false;
        }
        if ($('#RAI_Length').val() == '') {
            $('#EditError').html('属性长度不能为空！').show();
            return false;
        }
        return true;
    };
    function afterEdit(data) {
        if (data.result == 'success') {
            var tr = $('#tr_' + data.id);
            if (tr != null) {
                tr.find('td:eq(2)').html(data.name);
                tr.find('td:eq(4)').html(data.len);
            }
            $('#EditFieldSet').hide();
            alert('修改成功！');
        } else {
            $('#EditError').html(data.message).show();
        }
    };
</script>

@using (Ajax.BeginForm("RecuperAttachInfoEdit", new AjaxOptions()
    {
        OnSuccess = "afterEdit"
    }))
{
    <fieldset id="EditFieldSet">
        <legend>编辑属性&nbsp;<a href="javascript:void(0);" onclick="$('#EditFieldSet').hide();return false;">[取消]</a></legend>
        <input type="hidden" id="RAI_ID" name="id" />
        <label for="RAI_Name">属性名称：</label>
        <input type="text" id="RAI_Name" name="name" />
        <label for="RAI_Length">属性长度：</label>
        <input type="text" id="RAI_Length" name="length"
            onkeyup="this.value=this.value.replace(/\D/g,'')"
            onafterpaste="this.value=this.value.replace(/\D/g,'')" />
        <input type="submit" value="确定" onclick="return validateEdit();" />
        <p id="EditError" class="field-validation-valid"></p>
    </fieldset>
}
<br />
<table class="width">
    <tr>
        <th>所属功能</th>
        <th>属性序号</th>
        <th>属性名称</th>
        <th>属性类型</th>
        <th>属性长度</th>
        <th>操作</th>
    </tr>
    <tbody>

        @foreach (var field in Model.OrderBy(p => p.SettingKey).ThenBy(p => p.SortIdx))
        {            
            <tr class="tr-backColor@(dColor++ % 2)" id="tr_@(field.ID)">
                @if (field.SettingKey == "UserInfo")
                {
                    <td>患者基本信息</td>
                }
                else if (field.SettingKey == "EnHospital")
                {
                    <td>患者住院记录</td>
                }
                <td>@Html.DisplayFor(f => field.SortIdx)</td>
                <td>@Html.DisplayFor(f => field.SettingValue)</td>

                @if (field.SettingValueB == "System.String")
                {                        
                    <td>文本</td>
                }
                else if (field.SettingValueB == "System.Int32")
                {
                    <td>整数</td>
                }
                else if (field.SettingValueB == "System.Double")
                {
                    <td>浮点数</td>
                }
                else if (field.SettingValueB == "System.DateTime")
                {
                    <td>日期</td>
                }
                else if (field.SettingValueB == "System.Boolean")
                {
                    <td>是/否</td>   
                }
                else
                {
                    <td>&nbsp;</td>   
                }
                <td>@Html.DisplayFor(f => field.SettingValueC)</td>
                <td>
                    <a href="javascript:void(0);" onclick="initEditField('@field.ID','@field.SettingValue', '@field.SettingValueB', @field.SettingValueC);">编辑</a>
                </td>
            </tr>
        }
    </tbody>
</table>
